#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
使用 gTTS 生成音频文件的脚本
需要安装: pip install gtts
"""

from gtts import gTTS
import os

# 创建 sounds 目录
os.makedirs('sounds', exist_ok=True)

print("开始生成音频文件...\n")

# 生成字母发音 (A-Z)
print("生成字母发音...")
for i in range(26):
    letter = chr(65 + i)  # A-Z
    try:
        tts = gTTS(text=letter, lang='en', slow=False)
        filename = f'sounds/letter-{letter.lower()}.mp3'
        tts.save(filename)
        print(f"✓ 生成: letter-{letter.lower()}.mp3")
    except Exception as e:
        print(f"✗ 失败: letter-{letter.lower()}.mp3 - {e}")

print("\n生成单词发音...")

# 单词列表
words = [
    # 动物
    'cat', 'dog', 'bird', 'fish', 'rabbit', 'tiger', 'lion', 'elephant',
    # 水果
    'apple', 'banana', 'orange', 'grape', 'strawberry', 'watermelon', 'pear', 'peach',
    # 颜色
    'red', 'blue', 'green', 'yellow', 'purple', 'pink', 'black',
    # 数字
    'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'
]

for word in words:
    try:
        tts = gTTS(text=word, lang='en', slow=False)
        filename = f'sounds/word-{word}.mp3'
        tts.save(filename)
        print(f"✓ 生成: word-{word}.mp3")
    except Exception as e:
        print(f"✗ 失败: word-{word}.mp3 - {e}")

print("\n所有音频文件生成完成！")
print(f"共生成 {26 + len(words)} 个音频文件")
print("文件保存在 sounds/ 目录")

